package com.fzshang.shopping.api.controller;


import com.fzshang.shopping.commen.util.aliOSS.OSS_File;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 文件下传 前端控制器
 * </p>
 *
 * @author fzs
 * @since 2019-03-20
 */
@Controller
@RequestMapping("admin/file")
@Api(value = "文件下传controller", tags = {"文件下传类"})
public class FileController {


     @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "文件下传")
    public Object  uploadFile(MultipartFile file)throws Exception {
        /**
         * OSS下传文件到服务器
         */
            OSS_File oss_file = new OSS_File();
            String url =  OSS_File.uploadImage(file.getOriginalFilename(), file.getInputStream());
            System.out.println("文件名:"+file.getOriginalFilename());
            System.out.println("文件路径:"+url);
            Map map = new HashMap();
            map.put("code",0);
            map.put("msg","上传成功");
            map.put("data",url);

        return map;
    }



}